<!DOCTYPE html>
<html>
<!--
  (C) by Michael Peter Christen, mc (at) yacy.net
  licensed under a Creative Commons Attribution 2.0 Generic License (CC-BY 2.0)
-->
<head>
  <title id="title"></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <!-- scary MS stuff ahead to prevent that IE runs in "IE=EmulateIE10" mode which cannot run our JS code for some reason -->
  <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<!--
if you don't see the glyphicons in firefox and you opened this file from a local filesystem,
then a CORS security setting in firefox caused that.
No other browser is that strict and there is no work around. To see the glyphicons in firefox,
open about:config and set security.fileuri.strict_origin_policy to ‘false.’
-->
  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
  <meta name="Content-Language" content="English, Englisch" />
  <meta name="keywords" content="YaCy HTTP search engine spider indexer java network open free download Mac Windows Linux Software development" />
  <meta name="description" content="Software HTTP Freeware Home Page" />
  <meta name="copyright" content="Michael Christen et al." />
  
  <!-- Ensure proper rendering and touch zooming on mobile devices -->
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- Bootstrap core CSS -->
  <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">

  <script src="../bootstrap/js/jquery.min.js" type="text/javascript"></script>
  <script src="../bootstrap/js/bootstrap.min.js" type="text/javascript"></script>

  <script src="navigation.js" type="text/javascript"></script>
  <script src="../js/lib/underscore-min.js" type="text/javascript"></script>
  <script src="../js/lib/backbone-min.js" type="text/javascript"></script>
  <script src="../js/setup.js" type="text/javascript"></script> <!-- customization -->
  <script src="../js/yacysearch.js" type="text/javascript"></script>

  <!-- Custom styles for this template, i.e. navigation (move this to base.css) -->
  <link href="../css/bootstrap-base.css" rel="stylesheet">

  <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>
    <script src="../bootstrap/js/html5shiv.js"></script>
    <script src="../bootstrap/js/respond.min.js"></script>
  <![endif]-->

  <!-- old css styles -->
  <link rel="stylesheet" type="text/css" media="all" href="../css/base.css" />
  <link rel="stylesheet" type="text/css" media="screen" href="../css/style.css" />
  <!--[if lt IE 6]>
   <link rel="stylesheet" type="text/css" media="screen" href="../css/oldie.css" />
  <![endif]-->
  <!--[if lte IE 6.0]>
   <link rel="stylesheet" type="text/css" media="screen" href="../css/ie6.css" />
  <![endif]-->
  <!--[if lte IE 7.0]>
   <link rel="stylesheet" type="text/css" media="screen" href="../css/ie7.css" />
  <![endif]-->


  <script type="text/javascript">
  function handleArrowKeys(evt) {
    evt = (evt) ? evt : ((window.event) ? event : null);
    if (evt) {
      switch (evt.keyCode) {
        case 9:
        case 33:
          window.location.href = document.getElementById("nextpage").href;
          break;
        case 34:
          window.location.href = document.getElementById("prevpage").href;
          break;
        case 40:
      }
    }
  }
  document.onkeydown = handleArrowKeys;
  </script>
  <script type="text/javascript" src="../bootstrap/js/typeahead.jquery.min.js"></script>
  <script type="text/javascript">
     var suggestMatcher = function() {
       return function opensearch(q, cb) {
            $.getJSON(suggestUrl + "&q="+ q, function(data) {
               var parsed = [];
            for (var i = 0; i < data[0][1].length; i++) {
                var row = data[0][1][i];
                if (row) {
                    parsed[parsed.length] = {
                        data: [row],
                        value: row,
                        result: row
                    };
                };
            };
            cb(parsed);
          });
        };
      };
    $(document).ready(function() {
      $('#query').typeahead({hint:false,highlight:true,minLength:1}, {
        name: 'states',
        displayKey: 'value',
        source: suggestMatcher()
      });
    });
  </script>
  <style type="text/css">.twitter-typeahead {margin: 0px;padding: 0px;top:2px;}</style> <!-- fix for input window -->
</head>
<body id="yacysearch" onLoad="document.searchform.query.focus();">

  <!-- top navigation -->
  <div class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="container-fluid">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a id="homepage" class="navbar-brand" href="http://yacy.net" style="position:absolute;top:-6px;display:inline;white-space:nowrap;">
          <img id="logo" class="yacylogo" src="../images/YaCyLogo2011_60.png" alt="YaCy" style="height:auto; width:auto; max-width:200px; max-height:32px;vertical-align:middle">
        </a>
        <span id="topmenu" style="position:absolute;top:12px;left:80px;display:inline;white-space:nowrap;font-size:2em;"></span>
      </div>
      <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-right">
          <li id="header_help" class="dropdown">
            <a href="#" data-toggle="dropdown" class="dropdown-toggle"><span class="glyphicon glyphicon-question-sign"></span></a>
            <ul class="dropdown-menu">
              <li id="header_search"><a href="index.html?">Search Page</a></li>
              <li id="header_profile"><a href="about.html?">About This Page</a></li>
              <li id="header_usage"><a href="usage.html?">Usage of this page templates</a></li>
              <li id="header_tutorial"><a href="http://yacy.net/tutorials/">YaCy Tutorials</a></li>
              <li class="divider"></li>
              <li id="header_download"><a href="http://yacy.net" target="_blank"><i>external</i>&nbsp;&nbsp;&nbsp;Download YaCy</a></li>
              <li id="header_community"><a href="http://forum.yacy.de" target="_blank"><i>external</i>&nbsp;&nbsp;&nbsp;Community (Web Forums)</a></li>
              <li id="header_wiki"><a href="http://wiki.yacy.de" target="_blank"><i>external</i>&nbsp;&nbsp;&nbsp;Project Wiki</a></li>
              <li id="header_git"><a href="https://github.com/yacy/yacy_search_server/commits/master" target="_blank"><i>external</i>&nbsp;&nbsp;&nbsp;Git Repository</a></li>
              <li id="header_bugs"><a href="http://bugs.yacy.net" target="_blank"><i>external</i>&nbsp;&nbsp;&nbsp;Bugtracker</a></li>
            </ul>
          </li>
        </ul>
      </div>
    </div>
  </div>

  <div class="container-fluid">
    <div class="starter-template">
      <!-- body -->
    </div> <!-- close the starter-template, to open a row -->

    <div class="row">
      <div class="col-sm-8 col-sm-offset-4 col-md-9 col-md-offset-3 main" id="main">
        <form class="search small" name="searchform" action="#" method="get" accept-charset="UTF-8" style="position:fixed;top:6px;z-index:1052;max-width:500px;">
          <div class="input-group">
            <input name="query" id="query" type="text" class="form-control searchinput typeahead" size="40" maxlength="200" placeholder="Document Retrieval" value="" autofocus="autofocus" onFocus="this.select()" onclick="document.getElementById('Enter').innerHTML = 'search'"/>
            <div class="input-group-btn">
              <button id="Enter" name="Enter" class="btn btn-default" type="submit">search</button>
            </div>
          </div>
          <input type="hidden" name="nav" value="filetype,protocol,hosts,language,authors,namespace,topics" />
          <input type="hidden" name="maximumRecords" id="maximumRecords" value="10" />
          <input type="hidden" name="startRecord" id="startRecord" value="0" />
          <input type="hidden" name="layout" id="layout" value="paragraph" />
          <input type="hidden" name="contentdom" id="contentdom" value="text" />
          <input id="timezoneOffset" type="hidden" name="timezoneOffset" value="">
          <script>document.getElementById("timezoneOffset").value = new Date().getTimezoneOffset();</script>
        </form>

        <!-- type the number of results and navigation bar -->
        <div id="results"></div>
        <div class="progress" id="progress">
          <div class="progress-bar progress-bar-info" id="progressbar" role="progressbar" style="width:0%;">
            <span style="position:absolute;padding-left:10px;display:block;text-align:left;width:100%;color:black;" id="progressbar_text"></span>
          </div>
        </div>
        <script>
        if (document.getElementById("progressbar").getAttribute('class') != "progress-bar progress-bar-success") {
          document.getElementById("progressbar").setAttribute('style',"width:100%");
          document.getElementById("progressbar").setAttribute('style',"transition:transform 0s;-webkit-transition:-webkit-transform 0s;");
          document.getElementById("progressbar").setAttribute('class',"progress-bar progress-bar-success");
          window.setTimeout(fadeOutBar, 500);
        }
        </script>

        <!-- linklist begin -->
        <div id="downloadscript" style="clear:both;"></div>
        <div id="searchresults" style="clear:both;"></div>
        <!-- linklist end -->

        <span id="resNav" class="col-sm-12  col-md-12" style="display: inline;"></span>
      </div> <!-- close main -->

      <div class="col-sm-4 col-md-3 sidebar" id="sidebar">
        <!-- navigation begin -->
        <p class="navbutton"></p>
        <div class="btn-group btn-group-justified">
          <div class="btn-group btn-group-xs"><button type="button" id="sort_button_context" class="btn btn-default" onclick="document.getElementById('query').value=document.getElementById('query').value.replace(' /date','');document.searchform.submit();">Context Ranking</button></div>
          <div class="btn-group btn-group-xs"><button type="button" id="sort_button_date" class="btn btn-default" onclick="document.getElementById('query').value=document.getElementById('query').value + ' /date';document.searchform.submit();">Sort by Date</button></div>
        </div>

        <div id="searchnavigation"></div>
        <div id="downloadbutton"></div>

        <!-- navigation end -->

      </div> <!-- close sidebar -->
    </div> <!-- close row -->
  </div> <!-- close content container -->

  <!-- modify content according to query url attributes -->
  <script type="text/javascript">

  var rowCollection;

  function makeDownloadScript() {
    document.getElementById("downloadscript").innerHTML = "<div><pre>" + rowCollection.resultScript(); + "</pre><br/></div>";
    document.getElementById("downloadbutton").innerHTML = "<input id=\"downloadbutton\" type=\"button\" value=\"hide the download script\" onClick=\"hideDownloadScript();\"/>";
  }

  function hideDownloadScript() {
    document.getElementById("downloadscript").innerHTML = "";
    var dlb = document.getElementById("downloadbutton");
    if (dlb) dlb.innerHTML = "<input type=\"button\" value=\"create a download script\" onClick=\"makeDownloadScript();\"/>";
  }

  function hideScriptButton() {
    document.getElementById("downloadscript").innerHTML = "";
    var dlb = document.getElementById("downloadbutton");
    if (dlb) dlb.innerHTML = "";
  }

  document.getElementById("title").appendChild(document.createTextNode(headline));
  document.getElementById("topmenu").appendChild(document.createTextNode(headline));
  document.getElementById("homepage").setAttribute("href", homepage);
  document.getElementById("logo").setAttribute("src", logo);
  document.getElementById("query").setAttribute("placeholder", queryplaceholder);

  //  read command line options if present
  var query = new RegExp("[\\?&]query=([^&#]*)").exec(window.location.href);
  if (query == null || query.length < 2 || query[1].length == 0) {
    // remove progress and sidebar if there is no result
    document.getElementById("sidebar").innerHTML = "";
    document.getElementById("progress").remove();
  } else {
    query = decodeURIComponent(query[1].replace(/\+/g, '%20'));
    var startRecord = new RegExp("[\\?&]startRecord=([^&#]*)").exec(window.location.href);
    if (startRecord == null) startRecord = 0; else startRecord = startRecord[1];
    var maximumRecords = new RegExp("[\\?&]maximumRecords=([^&#]*)").exec(window.location.href);
    if (maximumRecords == null) maximumRecords = 10; else maximumRecords = maximumRecords[1];
    var layout = new RegExp("[\\?&]layout=([^&#]*)").exec(window.location.href);
    if (layout == null) layout = "paragraph"; else layout = layout[1];
    var contentdom = new RegExp("[\\?&]contentdom=([^&#]*)").exec(window.location.href);
    if (contentdom == null) contentdom = "text"; else contentdom = contentdom[1];
    document.getElementById("query").value=query;
    document.getElementById("maximumRecords").value=maximumRecords;
    document.getElementById("startRecord").value=startRecord;
    document.getElementById("layout").value=layout;

    //search for query
    var resulthtml = document.getElementById("searchresults");
    document.getElementById("progressbar_text").innerHTML = "loading...";
    if (maximumRecords == "") maximumRecords = 10;
    if (startRecord == "") startRecord = 0;
    if (query == null) query == "";

    var topicsModel = new ModifierModel({key:'topics:',query:query});
    var siteModel = new ModifierModel({key:'site:',query:query});
    var authorModel = new ModifierModel({key:'author:',query:query});
    var filetypeModel = new ModifierModel({key:'filetype:',query:query});
    var ext = filetypeModel.attributes.value;
    var hl = (layout=="paragraph") ? 'true' : 'false';

    var searchResult = new SearchModel({hl:hl,query:query,start:startRecord,rows:maximumRecords,servlet:"index.html",layout:layout,contentdom:contentdom});
    searchResult.fetch({
      timeout:10000,
      success:function(searchResult) {
        document.getElementById("progressbar_text").innerHTML = "parsing result...";
        rowCollection = new RowCollection({servlet:searchResult.attributes.servlet});
        rowCollection.add(searchResult.attributes.items);
        var totalResults = searchResult.attributes.totalResults.replace(/[,.]/,"");
        var navigation = searchResult.navigationCollection();

        // update navigation
        var topics = navigation.facet("topics");

        var topicsfacet = navigation.facet("topics");
        var topics = topicsfacet ? topicsfacet.facetElements() : {};
        
        var authorfacet = navigation.facet("authors");
        var author = authorfacet ? authorfacet.facetElements() : {};
        for (var key in author) {if (query.indexOf("author:(" + key + ")") >= 0) delete author[key];}
        
        var sitefacet = navigation.facet("domains");
        var site = sitefacet ? sitefacet.facetElements() : {};
        for (var key in site) {if (query.indexOf("site:" + key) >= 0) delete site[key];}
        
        var filetypefacet = navigation.facet("filetypes");
        var filetypes = filetypefacet ? filetypefacet.facetElements() : {};
        for (var key in filetypes) {if (query.indexOf("filetype:" + key) >= 0) delete filetypes[key];}
        
        if (layout == "images") {
          if (totalResults == 0)
            document.getElementById("progressbar_text").innerHTML = "no images found";
          else
            document.getElementById("progressbar_text").innerHTML = "found " + totalResults + " images, preparing...";
          resulthtml.innerHTML = rowCollection.resultImages();
          hideDownloadScript();
        } else if (layout == "paragraph") {
          if (totalResults == 0)
            document.getElementById("progressbar_text").innerHTML = "no documents found";
          else
            document.getElementById("progressbar_text").innerHTML = "found " + totalResults + " documents, preparing result list...";
          resulthtml.innerHTML = rowCollection.resultList();
          hideScriptButton();
        } else {
          if (totalResults == 0)
            document.getElementById("progressbar_text").innerHTML = "no documents found";
          else
            document.getElementById("progressbar_text").innerHTML = "found " + totalResults + " documents, preparing table...";
          resulthtml.innerHTML = rowCollection.resultTable();
          hideDownloadScript();
        }
       
        var searchnavigation = document.getElementById("searchnavigation");
        searchnavigation.innerHTML += searchResult.renderNavigation("Result Layout");
        if (topicsfacet) searchnavigation.innerHTML += topicsfacet.tagCloud(searchResult.attributes.servlet, topicsModel.attributes.key, topicsModel.attributes.value, 8, searchResult);
        if (filetypefacet) searchnavigation.innerHTML += filetypefacet.facetBox(searchResult.attributes.servlet, filetypeModel.attributes.key, filetypeModel.attributes.value, 8, searchResult);
        if (sitefacet) searchnavigation.innerHTML += sitefacet.facetBox(searchResult.attributes.servlet, siteModel.attributes.key, siteModel.attributes.value, 16, searchResult);
        if (authorfacet) searchnavigation.innerHTML += authorfacet.facetBox(searchResult.attributes.servlet, authorModel.attributes.key, authorModel.attributes.value, 16, searchResult);

        // generic facets
        var genericfacets = navigation.genericfacets();
        for (var i = 0; i < genericfacets.length; i++) {
            var genericfacet = genericfacets[i];
            var gModel = new ModifierModel({key:"/vocabulary/" + genericfacet + "/", query:query});
            var gfacet = navigation.facet(genericfacet);
            var g = gfacet ? gfacet.facetElements() : {};
            for (var key in gfacet) {
            	if (query.indexOf("/vocabulary/" + genericfacet + "/" + key) >= 0) delete gfacet[key];
            }
            searchnavigation.innerHTML += gfacet.facetBox(searchResult.attributes.servlet, gModel.attributes.key, gModel.attributes.value, 16, searchResult);
        }
        
        // update progress and navigation
        statistics(startRecord, maximumRecords, totalResults, window.location.href.replace(/&startRecord=[^&#]*/g,"")); //startRecord, maximumRecords, totalcount, navurlbase
      },
      error:function(searchResult) {
        document.getElementById("progressbar_text").innerHTML = "The search service is not available right now. Please try again.";
      }
    });

    // set buttons
    if (document.getElementById('query').value.indexOf(" /date") == -1) {
       document.getElementById("sort_button_context").setAttribute("class","btn btn-default active");
       document.getElementById("sort_button_context").setAttribute("onclick","");
    } else {
       document.getElementById("sort_button_date").setAttribute("class","btn btn-default active");
       document.getElementById("sort_button_date").setAttribute("onclick","");
    }
  }
  </script>

</body>
</html>
